/**
 * Created by John on 2016/7/8.
 */
function dispalayWords(cursor) {
    var words = cursor.map(function (word) {
        return word.word;
    });
    var wordStr = JSON.stringify((words));
    if (wordStr.length > 33) {
        wordStr = wordStr.slice(0, 30) + '...';
    }
    print(wordStr);
}

var mongo = new Mongo("localhost");
var wordsDB = mongo.getDB("BeginningMongoDB");
wordsColl = wordsDB.getCollection("word_stats");

var cursor = wordsColl.find({first: 'w'});
print("Words starting with w ascending: ");
dispalayWords(cursor.sort({word: 1}));

print();
print("Words starting with w descending");
cursor = wordsColl.find({first: 'w'});
dispalayWords(cursor.sort({word: -1}));

print();
print("A words sorted by last letter and by size: ");
cursor = wordsColl.find({first: 'a'});
dispalayWords(cursor.sort({last: 1}).sort({size: -1}));

print();
print("A words sorted by size then by last letter: ");
cursor = wordsColl.find({first: 'a'});
dispalayWords(cursor.sort({size: -1}).sort({last: 1}));

print();
print("A words sorted by last letter then by size: ");
cursor = wordsColl.find({first: 'a'});
dispalayWords(cursor.sort({last: 1}).sort({size: -1}));